/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.cef.generator.coreGenerator.base.entitygen.determination.Base;

import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
import com.inspur.edp.caf.generator.item.ClassGenerator;
import com.inspur.edp.caf.generator.item.ClassGeneratorContext;
import com.inspur.edp.caf.generator.method.ClassMethodGenerator;
import com.inspur.edp.caf.generator.property.ClassPropertyGenerator;
import com.inspur.edp.cef.designtime.api.operation.CommonDetermination;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.determination.Base.Method.DtmCanExecuteGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.determination.Base.Method.DtmExecuteGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.determination.Base.Property.DtmNameGenerator;
import com.inspur.edp.cef.generator.coreGenerator.base.entitygen.determination.DataTypeDtmsGenCtx;
import com.inspur.edp.cef.spi.determination.IDetermination;
import java.util.ArrayList;
import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;

public abstract class BaseDtmGenerator extends ClassGenerator {
  protected DataTypeDtmsGenCtx dtmsGenCtx;
  protected CommonDetermination dtm;

  public BaseDtmGenerator(DataTypeDtmsGenCtx dtmsGenCtx, CommonDetermination dtm) {
    super(dtmsGenCtx.dataTypeImplGenCtx.getParentContext().getProjContext().getCompilationUnitInfo());
    this.dtmsGenCtx = dtmsGenCtx;
    this.dtm = dtm;
  }


  // keyword:
  // ORIGINAL LINE: protected new BaseDtmGenCtx getContext() { return
  // (BaseDtmGenCtx)super.getContext(); }
  @Override
  protected BaseDtmGenCtx getContext() {
    return (BaseDtmGenCtx) super.getContext();
  }

  @Override
  protected final ClassGeneratorContext createClassInfoContext() {
    return createDtmGenContext();
  }

  protected BaseDtmGenCtx createDtmGenContext() {
    return new BaseDtmGenCtx(dtmsGenCtx, dtm);
  }

  @Override
  protected java.util.ArrayList<ModifierKeyword> getAccessModifier() {
    ArrayList<ModifierKeyword> result = new java.util.ArrayList<ModifierKeyword>(1);
    result.add(ModifierKeyword.PUBLIC_KEYWORD);
    return result;
  }

  protected abstract String getDtmType();

  public String getItemName() {
    return getName();
  }

  private static final String nameSuffix = "DtmAdaptor";

  @Override
  protected String getName() {
    return dtmsGenCtx.getDataType().getCode() + getDtmType() + dtm.getCode() + nameSuffix;
  }

  @Override
  protected ArrayList<TypeInfo> addParentInterfaces() {
    //TODO: caf暂不支持, 主动import
    dtmsGenCtx.dataTypeImplGenCtx.getParentContext().getProjContext().addImport(IDetermination.class.getName());
    dtmsGenCtx.dataTypeImplGenCtx.getParentContext().getProjContext().addImport(com.inspur.edp.cef.entity.changeset.Tuple.class.getName());
    return new java.util.ArrayList<TypeInfo>(
        java.util.Arrays.asList(new TypeInfo[] {new TypeInfo(IDetermination.class)}));
  }

  @Override
  protected final ArrayList<ClassPropertyGenerator> createPropertyGenerators() {
    return new java.util.ArrayList<ClassPropertyGenerator>(
        java.util.Arrays.asList(new ClassPropertyGenerator[] {getNamePropertyGenerator()}));
  }

  protected ClassPropertyGenerator getNamePropertyGenerator() {
    return new DtmNameGenerator(getContext());
  }

  @Override
  protected final java.util.ArrayList<ClassMethodGenerator> createMethodGenerators() {
    return new java.util.ArrayList<ClassMethodGenerator>(
        java.util.Arrays.asList(
            new ClassMethodGenerator[] {getExecuteGenerator(), getCanExecuteGenerator()}));
  }

  protected abstract DtmExecuteGenerator getExecuteGenerator();

  protected abstract DtmCanExecuteGenerator getCanExecuteGenerator();
}
